/**
 * Homework 6 CS 1332
 * @author Jihoon Lee
 */

import java.util.Arrays;

public class Sort<T extends Comparable<T>> implements SortInterface<T> {

	/**
	 * insertionSort() method
	 * @param array an array to sort
	 * Grab unsorted item and put it in a right place.
	 */
	
	public void insertionSort(T[] array) {
		
		T temp;
		
		for(int sortedItem=1; sortedItem<array.length; sortedItem++){
			for(int i=0; i<sortedItem; i++){
				if(array[sortedItem].compareTo(array[i])<0){
					temp=array[i];
					array[i]=array[sortedItem];
					array[sortedItem]=temp;
				}
			}
			//System.out.println(Arrays.toString(array));
		}
	}

	/**
	 * selectionSort() method.
	 * @param array
	 * Pick the lowest item and put it at the end of the sorted items.
	 */
	
	public void selectionSort(T[] array) {
		T lowest;
		int swapIndex;
		T temp;
		
		for(int j=0; j<array.length; j++){
			lowest = array[j];
			swapIndex = j;
			for(int i=j; i<array.length; i++){
				if(array[i].compareTo(lowest)<0){
					lowest = array[i];
					swapIndex = i;
				}
			}
			temp = array[j];
			array[j] = lowest;
			array[swapIndex] = temp;
			
			//System.out.println(Arrays.toString(array));
		}
	}

	@Override
	public void mergeSort(T[] array) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void quickSort(T[] array) {
		// TODO Auto-generated method stub
		
	}

}
